<?php
/**
 * Created by PhpStorm.
 * User: Zhoujinda
 * Date: 2016/4/8
 * Time: 15:27
 */

namespace Bbs\Api;

use Admin\Api\ConfigApi;

class FilterKeyWordsApi{

    const FILTER = "Bbs/FilterKeyWords/filter";


    /**
     * 关键词过滤
     */
    public function filter($posts,$replace='**'){

        $return = '';
        $result = apiCall(ConfigApi::GET_INFO,array(array('name'=>'FILTRATION_KEYWORDS')));
        if($result['status']){

            if(empty($result['info'])){
                $return = $posts;
            }else{
                $key_words = explode(',',$result['info']['value']);

                foreach($key_words as $val){
                    $val = trim(str_replace(array("/r/n", "/r", "/n"), "", $val));
                    $posts = str_replace($val,$replace,$posts);
                }

            }
            
        }

        $return = $posts;

        return array('status'=>true,'info'=>$return);

    }



}